﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.Dao.Core;
using Axis.BusinessObject.Core;
using Axis.Web.Administrator.Global;
using Axis.BusinessObject.Response;
namespace Sotipha.Web.Admin.Views.Login
{
   
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    CSecurity.USER_ID = 0;
                }
            }

            protected void btnLogin_Click(object sender, EventArgs e)
            {
                CCoreDao core = new CCoreDao();
                string userName = txtLoginName.Text.Trim();
                string password = txtPassword.Text.Trim();
                string inputValue = string.Format("<InputValue LoginName='{0}' Password='{1}' />", userName, password);
                CLoginResponse response = core.Login(inputValue);
                if (response.IsSuccessfull)
                {
                    CUserList user = response.UserList;
                    CSecurity.USER_ID = user.ID;
                    CSecurity.USER_NAME = user.LoginName;
                    CSecurity.USER_FIRSTNAME = user.FullName;
                    CSecurity.IS_ADMIN = true;
                    if (!string.IsNullOrEmpty(user.SecrectToken))
                    {
                        CSecurity.SECRECT_TOKEN = new Guid(user.SecrectToken);
                    }
                    Response.Redirect("~/Admin/Views/Home");
                }
                else
                {
                    pnlLoginError.Visible = true;
                    ltrLoginError.Text = "Login Failed. Please remember that passwords are case sensitive.";
                }
            }
        }
    
}